package com.agile.leetcode.concurrent.threadpool;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author KD
 * @Date 2021/2/25 9:36
 */
public class ThreadPoolExecutorDemo {
    public static void main(String[] args) {
        // 创建线程池
        ThreadPoolExecutor threadPoolExecutor=new ThreadPoolExecutor(2,5,5L, TimeUnit.MILLISECONDS,new LinkedBlockingDeque<>());
        for (int i = 0; i < 100; i++) {
            int k=i;
            threadPoolExecutor.execute(()->{
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"  "+k);
            });
        }
    }
}
